const { Types } = require('./type');
const { DataTypes } = require('sequelize/dist');
const sequelize = require('../config/sequelize');
const User = require('./user');

const Topic = sequelize.define('topic', {
  topic_id: {
    type: DataTypes.INTEGER,
    allowNull: false,
    primaryKey: true,
    autoIncrement: true,
  },
  title: {
    type: DataTypes.STRING,
  },
  author_id: {
    type: DataTypes.INTEGER,
    references: {
      model: User,
      key: 'user_id',
    },
  },
  views: {
    type: DataTypes.INTEGER,
  },
  content: {
    type: DataTypes.STRING,
  },
  brief: {
    type: DataTypes.STRING,
  },
  state: {
    type: DataTypes.INTEGER,
  },
  type: {
    type: DataTypes.INTEGER,
    references: {
      model: Types,
      key: 'id',
    },
  },
});

module.exports = Topic;
